
	footer.init();
	header.init('绑定手机号');

window.onload = function(){	
 var hander = null;
	$('body').on('click','#sendToTel',function(){
		$('#getcode').val('');
		var btn = $(this);
		var tel = $('#tel').val();
		console.log(tel);
		var reg=/^1[3,5,7,8,9]\d{9}$/;
		var time = 60;
		if(tel == "" || !reg.test(tel)){
			layer.msg('请输入正确的手机号');
			return false;
		}
		app.ajax(
			'/Index/Index/send',
			{
				mobile : tel
			},function(res){
				 $("#sendToTel").text("发送成功");
				 var time = 60;
               hander = setInterval(function () {
                    if (time <= 0) {
                        canSend = true;
                        clearInterval(hander);
                        btn.text("获取验证码");
                        btn.removeAttr("disabled");
                    }
                    else {
                        canSend = false;
                        time--;
                        btn.attr({ "disabled": "disabled" });
                        btn.text( time + "s后可重新发送");
                }
			},1000);
		});
	});

	
	$('body').on('click','.sure',function(){
		  clearInterval(hander);
       	$('#sendToTel').text("获取验证码");
        $('#sendToTel').removeAttr("disabled");
		var codeNum = $('#getcode').val();
		var tel = $('#tel').val();
		var reg=/^1[3,5,7,8,9]\d{9}$/;
		if(tel == "" || !reg.test(tel)){
			layer.msg('请输入正确的手机号');
			return false;
		}
		if(!codeNum){
			layer.msg('验证码不能为空');
			return false;
		}
		app.ajax(
			'/Member/Setting/update_mobile',
			{
				code : codeNum,
				mobile : tel
			},function(res){
				if(res.code == 200){
					layer.msg('注册成功');
					window.history.go(-1);
				}else if(res.code == 300){
					layer.msg(res.msg);
					$('#getcode').focus();
				}
			});
	});

	/**
	 * 验证手机输入
	 */
	$("#tel").on("input",function () {
		if ($(this).val().length > 11){
			$(this).val($(this).val().substring(0,11));
		}
	});
	$("#getcode").on("input",function () {
		if ($(this).val().length > 4){
			$(this).val($(this).val().substring(0,4));
		}
	});
}
